<div class="layui-input-block">
    <?if(count($category)<1){?>
        <a href="category_add.php?<?php echo $system_part;?>" class="layui-btn layui-btn-sm ">添加分类</a>
        <?;}?>

    <div id="category_select_box"></div>
    <input type="hidden" name="category_selected_list" id="category_selected_list"></input>
</div>




    <script>
        layui.use('tree', function(){
            var tree = layui.tree;

            //渲染
            var inst1 = tree.render({
                elem: '#category_select_box'  //绑定元素
                ,showCheckbox:true
                ,id:'category_select_box'
                ,data: <?echo $category_select_list?>
            });

        });
    </script>




<script>
    //分类树的提交和声明
    layui.use(['transfer', 'layer', 'util', 'form', 'tree'], function() {
        var $ = layui.$
            ,transfer = layui.transfer
            ,layer = layui.layer
            ,util = layui.util
            ,tree = layui.tree
            ,form = layui.form;

        // 确保DOM加载完成后再绑定事件
        $(document).ready(function() {
            form.on('submit(data_form_button)', function(data) {
                var checkData = tree.getChecked('category_select_box');
                $('#category_selected_list').val(JSON.stringify(checkData));
                console.log($('#category_selected_list').val());
                // 阻止表单默认提交

            });
        });
    });
</script>